package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/19.
 */
@HttpInlet(Conn.WALLET_INDEX)
public class MyBagListGet extends BaseAsyGet<MyBagListGet.MyBagListEntity> {

    public String user_id;
    public int page;

    public MyBagListGet(AsyCallBack<MyBagListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected MyBagListEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            MyBagListEntity myBagListEntity = new MyBagListEntity();

            JSONObject mainObject = object.optJSONObject("data");

            myBagListEntity.total = mainObject.optInt("total");
            myBagListEntity.per_page = mainObject.optInt("per_page");
            myBagListEntity.current_page = mainObject.optInt("current_page");

            JSONArray array = mainObject.optJSONArray("data");

            for (int i = 0; i < array.length(); i++) {

                JSONObject myBagEntityObject = array.optJSONObject(i);

                MyBagEntity myBagEntity = new MyBagEntity();

                myBagEntity._id = myBagEntityObject.optString("_id");
                myBagEntity.status = myBagEntityObject.optString("status");
                myBagEntity.orderNo = myBagEntityObject.optString("orderNo");
                myBagEntity.time = myBagEntityObject.optString("time");
                myBagEntity.title = myBagEntityObject.optString("title");
                myBagEntity.picUrl = Conn.IMAGE_BANNER_URL + myBagEntityObject.optString("picUrl");
                myBagEntity.address = myBagEntityObject.optString("address");
                myBagEntity.ticket_address = myBagEntityObject.optString("ticket_address");
                myBagEntity.poll = myBagEntityObject.optString("poll");

                myBagListEntity.myBagEntities.add(myBagEntity);

            }

            return myBagListEntity;

        }

            return null;
    }

    public class MyBagListEntity {

        public List<MyBagEntity> myBagEntities = new ArrayList();

        public int total, per_page, current_page;

    }

    public class MyBagEntity {

//        public String _id, showlistid, number, total, showtimes, exchangenum, title, picurl, exchangepicurl;

        public String _id, status, orderNo, title, time, picUrl, address, ticket_address, poll;

    }

}
